// *** LICENSE HEADER ***
// Filename: ./game.h
// This file is part of Nodewarz 0.1
// Nodewarz is a 3d OpenGL strategy game
// Copyright (C) 2007 CZestmyr
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// *** END LICENSE HEADER ***
#ifndef NODEWARS_GAME_H
#define NODEWARS_GAME_H

#include <SDL.h>
#include <GL/gl.h>
#include <cmath>
#include <cstring>
#include "Ieventhandler.h"
#include "engine.h"
#include "playerlist.h"
#include "player.h"
#include "camera.h"
#include "statusbar.h"
#include "particlesystem.h"
#include "gameboard.h"
#include "lightmanager.h"
#include "connector.h"
#include "gui.h"
#include "guielement.h"
#include "toggle.h"
#include "resourcelist.h"
#include "resource.h"
#include "helperfunctions.h"
#include "buttonids.h"

class playerList;
class engine;
class camera;
class statusBar;
class particleSystem;
class lightManager;
class gui;
class resourceList;

//Class that handles things related with a single game
class game: public IeventHandler {
    public:
        game(engine* newParent);
        ~game();

        //Creates a new game, taking the provided playerlist
        void NewGame(playerList* newPlayerlist = NULL);
        //Initialization when entering the game
        void InitGame();
        //Deinitialization at the end of the game
        void EndGame();

        //Updates the contents of the object
        void Update(Uint32 dt);
        //Draws the game (board, players, etc.)
        void Draw();

        //Loads the needed textures
        void LoadTextures();
        //Unloads all the used textures
        void UnloadTextures();

        //Following functions return pointers to various other game subsystems
        engine* GetEngine();
        playerList* GetPlayers();
        statusBar* GetStatusBar();
        particleSystem* GetParticleSystem();
        lightManager* GetLightManager();
        gui* GetGui();
        gameBoard* GetBoard();
        resourceList* GetResources();
        camera* GetCamera();

        //Following functions implement the interface IeventHandler
        void MouseClickEvent(int xCoordinate, int yCoordinate, bool right);
        void MouseReleaseEvent(int xCoordinate, int yCoordinate, bool right);
        void MouseMoveEvent(int newX, int newY, int relX, int relY);
        void KeyPressEvent(SDLKey key, char c);
        void KeyReleaseEvent(SDLKey key);
    private:
        playerList* players;
        engine* parent;
        camera* theCamera;
        statusBar* theBar;
        particleSystem* theParticleSystem;
        gameBoard* theBoard;
        lightManager* theLightManager;
        gui* myGui;
        resourceList* theResources;

        bool rightDrag;
        float cursor3DXPos, cursor3DYPos;

        GLuint cursorTexture;
        GLuint cursorTexture2;
        int timestamp;
};

#endif
